home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / buildImagePlaneMenu.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  5.9 KB  |  237 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  28 November 2000
  22. //
  23. //  Description:
  24. //      Builds a menu's and commands for the list of image planes
  25. //      associated with the current camera.
  26. //
  27.  
  28.  
  29. //
  30. //  Procedure Name:
  31. //      getPanelCamera
  32. //
  33. //  Description:
  34. //      Get the camera shape name in the model panel.
  35. //
  36. //  Input Arguments:
  37. //      None.
  38. //
  39. //  Return Value:
  40. //      An empty string is returned if there is no camera.
  41. //
  42. proc string getPanelCamera( string $modelPanel )
  43. {
  44.     string $cameraShapeName = "";
  45.  
  46.     if (`modelPanel -exists $modelPanel`) {
  47.         string $camera = `modelPanel -q -camera $modelPanel`;
  48.  
  49.         if ($camera != "") {
  50.             // Get current camera's shape     
  51.             string $cameraShapes[] = `listRelatives -shapes $camera`;
  52.  
  53.             if (size($cameraShapes) > 0) {
  54.                 $cameraShapeName = $cameraShapes[0];
  55.             }
  56.         }
  57.  
  58.         if ($cameraShapeName == "") {
  59.             warning ($modelPanel+" does not have a valid camera");
  60.         }
  61.     }
  62.     else {
  63.         warning ($modelPanel+" is not a model panel");
  64.     }
  65.  
  66.     return $cameraShapeName;
  67. }
  68.  
  69.  
  70. //
  71. //  Procedure Name:
  72. //      getImagePlaneList
  73. //
  74. //  Description:
  75. //      Create a list of image planes for the current camera view.
  76. //
  77. //  Input Arguments:
  78. //      None.
  79. //
  80. //  Return Value:
  81. //      Array of image plane names
  82. //
  83. proc string[] getImagePlaneList( string $modelPanel )
  84. {      
  85.     string $result[];
  86.  
  87.     string $cameraShape = `getPanelCamera $modelPanel`;
  88.  
  89.     if ($cameraShape != "") {
  90.         $result = `listConnections ($cameraShape + ".imagePlane")`;
  91.     }
  92.  
  93.     return $result;
  94. }
  95.  
  96.  
  97. //
  98. //  Procedure Name:
  99. //      createImportedImagePlane
  100. //
  101. //  Description:
  102. //      Creates an image plane with the file name provided.
  103. //
  104. //  Input Arguments:
  105. //      imageName : image file name from the browser
  106. //      type : file type
  107. //
  108. //  Return Value:
  109. //      Returns 1 so that the file browser will close.
  110. //
  111. global proc int createImportedImagePlane (string $modelPanel,
  112.                                           string $imageName,
  113.                                           string $type)
  114. {
  115.     // Check whether an image filename was provided 
  116.  
  117.     if ( $imageName != "" ) {
  118.         string $cameraShape = `getPanelCamera $modelPanel`;
  119.  
  120.         if ($cameraShape != "") {
  121.             // create image plane     
  122.             string $newImagePlane = `shadingNode -asUtility imagePlane`;
  123.  
  124.                 // set the image plane type to image file
  125.             setAttr ($newImagePlane + ".type") 0;          
  126.  
  127.             // assign the imageName to the imagePlane
  128.             setAttr ($newImagePlane + ".imageName")
  129.                 -type "string" $imageName; 
  130.     
  131.             cameraImagePlaneUpdate $cameraShape $newImagePlane;
  132.         }
  133.     }
  134.  
  135.     return 1;
  136. }
  137.  
  138.  
  139. //
  140. //  Procedure Name:
  141. //      importImagePlane
  142. //
  143. //  Description:
  144. //      Imports an image file as an image plane.
  145. //
  146. //  Input Arguments:
  147. //      None.
  148. //
  149. //  Return Value:
  150. //      None.
  151. //
  152. global proc importImagePlane( string $modelPanel )
  153. {      
  154.     // Do we have a camera ?
  155.  
  156.     if (`getPanelCamera $modelPanel` != "") {
  157.         // Set the current working directory to the project's
  158.         // sourceimage directory
  159.     
  160.         string $workspace = `workspace -q -fullName`;     
  161.  
  162.         setWorkingDirectory $workspace "image" "sourceImages";
  163.     
  164.         string $cmd = ("createImportedImagePlane " + $modelPanel);
  165.  
  166.         fileBrowser ($cmd, "Open", "image", 0);        
  167.     }
  168. }
  169.  
  170.  
  171. global proc buildImagePlaneList (string $parent, string $modelPanel) 
  172.  
  173. //
  174. // builds a menu list of image planes for the current camera
  175. //
  176.  
  177. {
  178.     setParent -m $parent;
  179.  
  180.     menu -e -deleteAllItems $parent;
  181.  
  182.     string $imagePlanes[] = `getImagePlaneList $modelPanel`;
  183.  
  184.     for ($imagePlane in $imagePlanes) {
  185.         string $editCommand = "select " + $imagePlane +
  186.             "; showEditor " + $imagePlane;
  187.  
  188.         menuItem -tearOff false 
  189.             -l $imagePlane
  190.             -command $editCommand;
  191.  
  192.     }
  193.  
  194. }
  195.  
  196.  
  197. //
  198. //  Procedure Name:
  199. //      buildImagePlaneMenu
  200. //
  201. //  Description:
  202. //      Builds  a menu for managing  image  planes in the model pane's
  203. //      view menu.
  204. //
  205. //  Input Arguments:
  206. //      parent : parent menu to build menu for.
  207. //
  208. //  Return Value:
  209. //      None.
  210. //
  211. global proc buildImagePlaneMenu (string $parent, string $modelPanel)
  212. {
  213.     string $imagePlanes[] = `getImagePlaneList $modelPanel`;
  214.  
  215.     int $anyImagePlanes = size($imagePlanes) > 0;
  216.  
  217.     setParent -m $parent;
  218.  
  219.     menu -e -deleteAllItems $parent;
  220.  
  221.     menuItem -l "Import Image..."
  222.          -c ("importImagePlane " + $modelPanel)
  223.         importImageMenuItem;
  224.  
  225.     string $postCommand =
  226.         ("buildImagePlaneList imagePlaneEditSubMenu " + $modelPanel);
  227.  
  228.     menuItem -l "Image Plane Attributes" 
  229.          -enable $anyImagePlanes 
  230.          -subMenu true 
  231.          -tearOff false 
  232.          -postMenuCommand $postCommand
  233.         imagePlaneEditSubMenu;
  234.         
  235.     setParent -m ..; // from imagePlaneSubmenu
  236. }
  237.